﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>资源库单位登记</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
<style type="text/css">
html,body {
	font-size: 12px;
	padding: 0;
	margin: 0;
	border: 0;
	height: 100%;
	overflow: hidden;
}
</style>
</head>
<body>
	<fieldset style="border:solid 1px #aaa;padding:3px;">
	<legend>单位基本信息</legend>
	<form id="form1" method="post">
	<input name="aab001" id="aab001" class="mini-hidden" />
	<div style="padding-left:11px;padding-bottom:5px;">
	<table style="table-layout:fixed;">					
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>单位名称：</td>
		<td style="width:550px;"colspan="3"><input name="aab004" style="width:97%" id="unit_name" class="mini-textbox"
							 					required="true"    maxlength="25" emptyText="请输入单位名称"  /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>单位性质：</td>
		<td style="width:180px;"><input id="aab019" name="aab019" class="mini-combobox" style="width:84%;" textField="aaa103" 
										valueField="aaa102" emptyText="请选择..." showNullItem="true" nullItemText="请选择..."
							     required="true"       url="${pageContext.request.contextPath }/unit.do?method=getselect&lx=AAB019"
							             /></td>
	</tr>
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;">统一社会信用代码：</td>
		<td style="width:180px;"><input name="aab998" style="width:84%" id="credit_id" class="mini-textbox"
							            allowInput="true"  maxlength="18"
							            emptyText="统一社会信用代码(18位)" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;">组织机构代码：</td>
		<td style="width:180px;"><input name="aab003" style="width:90%" id="organization_id" class="mini-textbox"
										maxlength="10" allowInput="true"  
										 emptyText="请输入组织机构代码" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>地税登记证号：</td>
		<td style="width:180px;"><input name="aab030" style="width:84%" class="mini-textbox" maxlength="15"
									required="true"		emptyText="请输入地税登记证号" allowInput="true" /></td>
	</tr>
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>联系人：</td>
		<td style="width:180px;"><input name="aae004" style="width:84%" class="mini-textbox" required="true"
										maxlength="15" emptyText="请输入联系人" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>联系电话：</td>
		<td style="width:180px;"><input name="aae005" style="width:90%" class="mini-textbox" required="true"
										vtype="int" maxlength="11" emptyText="请输入联系电话" /></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>法定代表人姓名：</td>
		<td style="width:180px;"><input name="aab013" style="width:84%" class="mini-textbox" required="true"
										maxlength="15" emptyText="请输入法定代表人姓名" /></td>
	</tr>
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>法定代表人证件类型：</td>
		<td style="width:180px;"><input name="aae018" class="mini-combobox" valueField="aaa102" textField="aaa103"
										style="width:84%" id="documenttype" required="true"
						url="${pageContext.request.contextPath }/unit.do?method=getselect&lx=AAC058"
						 emptyText="请选择..." showNullItem="true" nullItemText="请选择..."/></td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>法定代表人证件号码：</td>
		<td style="width:180px;"><input name="aab014" style="width:90%" class="mini-textbox" maxlength="18"required="true"
										  emptyText="请输入法定代表人证件号码" />
		</td>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>法定代表人联系电话：</td>
		<td style="width:180px;"><input name="aab015" style="width:84%" class="mini-textbox" vtype="int;minLength:7" maxlength="11"
									required="true"	 emptyText="请输入法定代表人联系电话" /></td>
	</tr>		
	<tr>
		<td style="width:180px;text-align:right;white-space:nowrap;"><span style="color:red;">*</span>邮政编码：</td>
		<td style="width:180px;"><input name="aae007" style="width:84%" class="mini-textbox" 
								required="true"		vtype="int" maxlength="6" emptyText="请输入邮政编码" /></td>
	</tr>			
	</table>
	</div>
	<div style="text-align:center;padding:10px;">
	<a class="mini-button" onclick="saveData1" iconCls="icon-ok" style="width:60px;margin-right:20px;">确定</a>
	<a class="mini-button" iconCls="icon-remove" onclick="onReset" style="width:60px;margin-right:20px;">重置</a>
	</div>
	</form>
	</fieldset>

<script type="text/javascript">
	var judge = false;
	var judge2 = false;
	mini.parse();
	var form = new mini.Form("form1");
	function SaveData() {
		var o = form.getData();			
		form.validate();
		if (form.isValid() == false) return;
		if(form.isValid()==true){
	      	   mini.mask({el: document.body,cls: 'mini-mask-loading',html: '保存中...'});
	      	 }
		var json = mini.encode([o]);
		$.ajax({
			url : "/zyk/unit.do?method=saveunit",
			type : 'post',
			data : {
				data : json
			},
			cache : false,
			success : function(text) {
				mini.unmask();
				if(text.length > 5)	{
					var ssss = text.substring(0,4);
					var ssss1 = text.substring(0,7);
					if(ssss == "hint")
					{
						var tttt = text.substring(5,text.length);
						if(confirm(tttt)==true)
						{
							saveDatas();
							return;
						}
						else
						{
							//form.clear();
							CloseWindow("save");
							return ;
						}
					}
					/*
					if(ssss1== "组织机构代码与"){
						var tttt = text.substring(0,text.length);
						if(confirm(tttt)==true)
						{
							saveDatas();
							return;
						}
						else 
						{
							CloseWindow("save");
							return ;
						}
					}
					*/
				}
				if(text == "error")
				{
					mini.alert("数据输入格式不规范,请检查数据格式");
					CloseWindow("save");
					return ;
				}
				
				if(!isNaN(text))
				{
			     mini.alert("登记成功，你的劳动保障证号为：" + text);
				 form.clear();
				 CloseWindow("save");
				 return ;
				} else {
					mini.alert(text);
				}
				
				CloseWindow("save");
			},
			error : function(jqXHR, textStatus, errorThrown) {
				mini.alert(jqXHR.responseText);
				CloseWindow();
			}
		});
	}
	
	
	function saveDatas()
	{
		var o = form.getData();			
		form.validate();
		if (form.isValid() == false)
		return;
		var json = mini.encode([o]);
		$.ajax({
			url : "/zyk/unit.do?method=saveunit1",
			type : 'post',
			data : {
				data : json
			},
			cache : false,
			success : function(text) {
				mini.unmask();
				mini.alert("登记成功，你的劳动保障证号为：" + text);
				
				form.clear();
				CloseWindow("save");
			},
			error : function(jqXHR, textStatus, errorThrown) {
				mini.alert(jqXHR.responseText);
				CloseWindow();
			}
		});
	}
	
	
	function loading() {
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '加载中...'
        });
        setTimeout(function () {
            mini.unmask(document.body);
        }, 2000);
    }
		////////////////////
		//标准方法接口定义
	function SetData(data) {
		if (data.action == "edit") {
		//跨页面传递的数据对象，克隆后才可以安全使用
			data = mini.clone(data);
			$.ajax({
				url : "/zyk/unit.do?method=getunitdata&id=" + data.id,
				cache : false,
				success : function(text) {
					var o = mini.decode(text);
					form.setData(o);
					form.setChanged(false);
				}
			});
		}
	}
	function GetData() {
		var o = form.getData();
		return o;
	}
	function ondwChanged() {
		var credit_id = mini.get("#credit_id");
		var organization_id = mini.get("#organization_id");
		var landtax = mini.getbyName("aab030");
		var f = mini.get("#aab019").getValue();
		//企业
		if (f == "10") {
			landtax.setValue("");
			credit_id.setEmptyText("统一社会信用代码(18位)");
			credit_id.setAllowInput(true);
			credit_id.setRequired(false);
			organization_id.setAllowInput(true);
			organization_id.setRequired(false);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");
		}
		//机关、事业单位
		if (f == "30" || f == "50") {
			landtax.setValue("");
			credit_id.setValue("");
			credit_id.setEmptyText("");
			credit_id.setAllowInput(false);
			organization_id.setAllowInput(true);
			organization_id.setRequired(true);
			landtax.setAllowInput(false);
			landtax.setEmptyText("");
		}
		//社会团体
		if (f == "70") {
			credit_id.setValue("");
			credit_id.setEmptyText("");
			credit_id.setAllowInput(false);
			organization_id.setAllowInput(true);
			organization_id.setRequired(true);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");
		}
		if (f == "81") {
			credit_id.setValue("");
			landtax.setValue("");
			credit_id.setEmptyText("统一社会信用代码(18位)");
			credit_id.setAllowInput(true);
			credit_id.setRequired(false);
			organization_id.setAllowInput(true);
			organization_id.setRequired(false);
			landtax.setAllowInput(true);
			landtax.setEmptyText("请输入地税登记证号");
		}
	}
	function onOk(e) {
		var credit_id = mini.get("#credit_id").getValue();
		var organization_id = mini.get("#organization_id").getValue();
		var f = mini.get("#aab019").getValue();
		if (f == '10' && credit_id == '' && organization_id == '') {
			mini.alert("统一社会信用代码、组织机构代码不能同时为空");
			return;
			judge2 = false;
		} else{
			judge2=true;
		}
		if (f == '10' && credit_id != '' && organization_id != '') {
			mini.alert("统一社会信用代码、组织机构代码不能同时采集");
			mini.getbyName("aab998").setValue();
			mini.getbyName("aab003").setValue();
			return;
		} else{
			judge= true;
		}
		var AAB001 = mini.getbyName("aab001").getValue();
		if (AAB001.length > 0) {
			CheckNumber(e);
		}
		if (judge && judge2) {	
			SaveData();
		} 
	}	
	function onReset(e) {
		form.clear();
	}
	function CheckNumber(e) {
		var AAB998 = mini.getbyName("aab998").getValue();
		var f = mini.get("#aab019").getValue();
		if (AAB998.length<18 && AAB998.length>=1) {
			mini.alert("统一社会信用代码必须为18位");
			judge = false;
		} else {
			checkCriditId();
		}
	}
	function onNumber(e) {
		var zjlx = mini.get("#documenttype").getValue();
		var aab014 = mini.getbyName("aab014").getValue().trim();
		if (zjlx == '01') {
			$.ajax({
				url : "/zyk/unit.do?method=checksfz&id=" + aab014,
				success : function(res) {
				if ("0" != res) {
					mini.alert(res);
					//mini.getbyName("aab014").setValue("");
				}
				}
			});
		}
	}
	function isNumber(v) {
		var tel = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
		var flag = true;
		if (!tel.test(v)) {
			flag = false;
		} else {
			var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10,5, 8, 4, 2);
			var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5','4', '3', '2');
			var nTemp = 0, i;
			var temp = v.substring(0, 17);
			for (i = 0; i < temp.length; i++) {
				nTemp += temp.substr(i, 1) * arrInt[i];
			}
			temp += arrCh[nTemp % 11];
			if (temp != v) {
				flag = false;
			}
		}
			return flag;
		}
	//发ajax请求到后台判断用户名是否重复
	function checkName() {	  
		var name = mini.getbyName("aab004").getValue().trim();
		$.ajax({
			url : "/zyk/unit.do?method=getunitname",
			cache: false,
			dataType : 'JSON',
			data : {
				name : name
			},
			success : function(result) {
			//已经存在该名字提示用户
				if (result != null) {
					mini.get("#unit_name").setValue();
					mini.alert("该单位已注册，请重新输入");
					judge = false;
				} else {
					judge = true;
				}
			}
		});
	}
	function isOrganization(v) {
		var re = new RegExp("^([0-9A-Z]){8}-[0-9|X]$");
		if (re.test(v))
			return true;
			return false;
	}
	//检测组织ID是否重复
	function CheckOrganizationId(v) {
		if (v.isValid) {
			if (isOrganization(v.value) == false && v.value != '') {
				v.errorText = "组织机构输入不合法";
				v.isValid = false;
			}
		}
		var id = mini.get("#organization_id").getValue().trim();
		$.ajax({
			url : "/zyk/unit.do?method=getunitorganizationids",
			dataType : 'JSON',
			data : {
				id : id
			},
			success : function(result) {
			//已经存在组织机构代码字提示用户
				if (result != null) {
					mini.get("#organization_id").setValue();
					mini.alert("组织机构代码重复，请重新输入");
					judge = false;
				} else {
					judge = true;
				}
			}
		});
	}
	function checkCriditId() {
		var id = mini.get("#credit_id").getValue().trim();
		$.ajax({
			url : "/zyk/unit.do?method=getunitcreditid",
			dataType : 'JSON',
			data : {
				id : id
			},
			success : function(result) {
				//已经存在该社会信用代码提示用户
				if (result != null) {
					mini.get("#credit_id").setValue();
					mini.alert("统一社会信用代码已注册，请重新输入");
					judge = false;
				} else {
					judge = true;
				}
			}
		});
	}
	function onDrawDate(e) {
		var date = e.date;
		var d = new Date();
		if (date.getTime() >= d.getTime()) {
			e.allowSelect = false;
		}
	}
	
	function saveData1()
	{
		SaveData();
	}
	
	 function checkData()
	    {
	      var data=mini.getbyName("aab003").getValue().trim();
	      
	      if(data=="" || data.length < 9 || data.length > 10)
	      {
	        mini.alert("请输入9位或者十位的组织机构代码！");
	        return;
	      }
	      
	      if(data.length == 9 && !checkRate(data))
	      {
	        mini.alert("9位组织机构代码为全数字！");
	        return ;
	      }
	       if(data.length == 10 )
	      {
	        var data1 = data.substr(8,1);
	        
	        if(data1 != "-")
	        {
	          mini.alert("10位组织机构代码的倒数第二位是‘-’！");
	          return ;
	        }
	        var data2 = data.substr(0,8) + data.substr(9,1);
	        //alert(data2);
	        if(!checkRate(data2))
	        {
	          mini.alert("10位组织机构代码除‘-’其余皆为数字！");
	          return ;
	        }
	      }
	      
	    }
	function checkRate(value)
	{
	 var re = /^[0-9]+.?[0-9]*$/;   //判断字符串是否为数字,//若判断正整数，则后边是：/^[1-9]+[0-9]*]*$/
	 if (!re.test(value))
	 {
	  return false;
	 }
	 return true ;
	}

	
	</script>
</body>
</html>
